package com.architecture.core.entity;

import javax.persistence.*;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * LoginAction: Administrator
 * Date: 12-3-28
 * Time: 上午10:35
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "CORE_USER")
//@TypeDefs({@TypeDef(name = "encryptedString",typeClass = EncryptedStringType.class,parameters = {@Parameter(name = "password",value = "jasypt")})})
public class User extends BaseEntity {

    @Column(name = "USERNAME", nullable = false, unique = true)
    private String username;            //自然键，hibernate维护username为唯一值,但在数据库中不是主键

    //    @Type(type = "encryptedString")
    @Column(name = "PASSWORD")
    private String password;

    @Column(name = "USER_LEVEL")
    private int level;              //用户级别

    @Column(name = "USER_TYPE")
    private int type;            //用户类型。1.管理员；2.普通用户

    @ManyToOne(fetch = FetchType.EAGER, targetEntity = User.class, cascade = CascadeType.ALL)
    @JoinColumn(name = "USER_ID")
    private User user;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "user", targetEntity = User.class, cascade = CascadeType.ALL)
    private List<User> userList;

    @ManyToOne(fetch = FetchType.EAGER, targetEntity = Group.class, cascade = CascadeType.ALL)
    @JoinColumn(name = "GROUP_ID")
    private Group group;

    @ManyToMany(fetch = FetchType.LAZY, targetEntity = Category.class, cascade = CascadeType.ALL)
    @JoinTable(name = "EX_USER_CATEGORY", joinColumns = {@JoinColumn(name = "USER_ID")}, inverseJoinColumns = {@JoinColumn(name = "CATEGORY_ID")})
    private List<Category> categoryList;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public List<User> getUserList() {
        return userList;
    }

    public void setUserList(List<User> userList) {
        this.userList = userList;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public List<Category> getCategoryList() {
        return categoryList;
    }

    public void setCategoryList(List<Category> categoryList) {
        this.categoryList = categoryList;
    }

    public Group getGroup() {
        return group;
    }

    public void setGroup(Group group) {
        this.group = group;
    }
}
